package com.dhcc.DRGsHosp.web.controller;

import com.dhcc.DRGsHosp.facade.PropertiesFacade;
import org.codehaus.jackson.map.ObjectMapper;
import org.openkoala.koala.commons.InvokeResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @title		:PropertiesController.java
 * @description	:配置文件读写--通用drgs
 * @author		:lileizheng
 * @date		:2016年9月27日
 * @version     :1.0
 * @copyright   :DHCC 2013-2014 
 */
@Controller("drgsHospWebController34")
@RequestMapping("/properties")
public class PropertiesController {

	@Autowired
	private PropertiesFacade propertiesFacade;
	
	@ResponseBody
	@RequestMapping(value = "getProperties")
	public InvokeResult getProperties(String fileName){
		return propertiesFacade.getProperties(fileName);
	}
	
	@ResponseBody
	@RequestMapping(value = "getProperty")
	public InvokeResult getProperty(String key){
		return propertiesFacade.getProperty(key);
	}
	
	@ResponseBody
	@RequestMapping(value = "setProperty")
	public InvokeResult setProperties(String data){
		ObjectMapper objectMapper = new ObjectMapper();
		Map<String, String> json;
		try {
			json = objectMapper.readValue(data, Map.class);
		} catch (Exception e) {
			e.printStackTrace();
			json = new HashMap<String, String>();
		}
		return propertiesFacade.setProperties(json);
	}
}
